package org.linlinjava.litemall.admin.web2.order;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.linlinjava.litemall.admin.service2.AOrderService;
import org.linlinjava.litemall.admin.service2.AUserService;
import org.linlinjava.litemall.admin.web2.order.req.OReq;
import org.linlinjava.litemall.admin.web2.order.req.OReq2;
import org.linlinjava.litemall.admin.web2.order.req.OReq3;
import org.linlinjava.litemall.admin.web2.order.resp.*;
import org.linlinjava.litemall.admin.web2.user.resp.UResp1;
import org.linlinjava.litemall.core.util.R;
import org.linlinjava.litemall.core.util.Util;
import org.linlinjava.litemall.db.enumeration.Const;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单中心
 */

@RestController
@Api("订单中心")
@RequestMapping("/order")
public class AOrderController {

    private static Logger log = LoggerFactory.getLogger(AOrderController.class);

    @ApiOperation(value = "下拉框-获取商铺店")
    @GetMapping("/getShop")
    public Object getShop() {
        log.info("获取商铺店");
        List<Integer> identities = Util.aList(3);
        identities.add(Const.Identity.FRANSHISED);
        identities.add(Const.Identity.FRANSHISED2);
        identities.add(Const.Identity.DIRECT);
        List<UResp1> resList = userService.getShop(identities);
        return R.ok(resList);
    }

    @ApiOperation(value = "下拉框-获取提货点")
    @GetMapping("/getPickUp")
    public Object getPickUp() {
        log.info("获取商铺店");
        List<Integer> identities = Util.aList(1);
        identities.add(Const.Identity.SELFMENTION);
        List<UResp1> resList = userService.getShop(identities);
        return R.ok(resList);
    }

    @ApiOperation(value = "订单管理-待付款列表")
    @PostMapping("/list1")
    @ApiResponses({@ApiResponse(response = OResp1.class, message = "正常响应", code = 200)
    })
    public Object list1(@RequestBody OReq req) {
        log.info("待付款列表");
        return orderService.list1(req);
    }


    @ApiOperation(value = "订单管理-已关闭")
    @PostMapping("/list2")
    @ApiResponses({@ApiResponse(response = OResp2.class, message = "正常响应", code = 200)
    })
    public Object list2(@RequestBody OReq req) {
        log.info("已关闭列表");
        return orderService.list2(req);
    }

    @ApiOperation(value = "订单管理-已完成")
    @PostMapping("/list3")
    @ApiResponses({@ApiResponse(response = OResp3.class, message = "正常响应", code = 200)
    })
    public Object list3(@RequestBody OReq req) {
        log.info("已完成列表");
        return orderService.list3(req);
    }

    @ApiOperation(value = "订单管理-待发货")
    @PostMapping("/list4")
    @ApiResponses({@ApiResponse(response = OResp4.class, message = "正常响应", code = 200)
    })
    public Object list4(@RequestBody OReq req) {
        log.info("待发货列表");
        return orderService.list4(req);
    }

    @ApiOperation(value = "订单管理-已发货")
    @PostMapping("/list5")
    @ApiResponses({@ApiResponse(response = OResp5.class, message = "正常响应", code = 200)
    })
    public Object list5(@RequestBody OReq req) {
        log.info("已发货列表");
        return orderService.list5(req);
    }

    @ApiOperation(value = "订单管理-已支付未成团")
    @PostMapping("/list6")
    @ApiResponses({@ApiResponse(response = OResp6.class, message = "正常响应", code = 200)
    })
    public Object list6(@RequestBody OReq2 req) {
        log.info("已支付未成团");
        return orderService.list6(req);
    }

    @ApiOperation(value = "订单管理-订单详情")
    @GetMapping("/orderDetail")
    @ApiResponses({@ApiResponse(response = OResp7.class, message = "正常响应", code = 200)
    })
    public Object orderDetail(@RequestParam Integer id) {
        log.info("订单管理-订单详情[id={}]", id);
        Object o = orderService.orderDetail(id);
        return o;
    }

    @ApiOperation(value = "获取配送员")
    @GetMapping("/getSendPerson")
    @ApiResponses({@ApiResponse(response = OResp8.class, message = "正常响应", code = 200)
    })
    public Object getSendPerson() {
        log.info("获取配送员");
        List<OResp8> sendPerson = userService.getSendPerson();
        return R.ok(sendPerson);
    }

    @ApiOperation(value = "订单配送")
    @PostMapping("/sendOrder")
    public Object sendOrder(@RequestBody OReq3 req) {
        log.info("订单配送");
        return orderService.sendOrder(req);
    }

    @Autowired
    private AUserService userService;
    @Autowired
    private AOrderService orderService;
}
